package com.dqhl.community.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.model.ApplianceRepairType;
import com.dqhl.community.util.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/9/11.
 */
public class ApplianceRepairTypeAdapter extends BaseMyAdapter {

    private List<ApplianceRepairType> type_list;
    private int selectedPosition=0;
    public ApplianceRepairTypeAdapter(Context context, List<ApplianceRepairType> list) {
        super(context);
        this.type_list = list;

    }

    @Override
    public int getCount() {
        return type_list.size();
    }

    @Override
    public Object getItem(int i) {
        return type_list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public void clearSelection(int position) {
        selectedPosition = position;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.layout_repair_project_item, viewGroup, false);
        }

        ImageView iv_repair_item = ViewHolder.get(view, R.id.iv_repair_item);
        TextView tv_repair_item = ViewHolder.get(view, R.id.tv_repair_item);
        ApplianceRepairType applianceRepairType = type_list.get(i);
        tv_repair_item.setText(applianceRepairType.getType());
        if ("洗衣机".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_washer);
        } else if ("微波炉".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_microwave);
        } else if ("冰箱".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_freezer);
        } else if ("抽油烟机".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_smoke);
        } else if ("热水器".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_water);
        } else if ("空调".equals(applianceRepairType.getType())) {
            iv_repair_item.setImageResource(R.drawable.ic_air);
        }
        if(selectedPosition==i){
            tv_repair_item.setTextColor(Color.parseColor("#ff6501"));
            view.setBackgroundResource(R.color.grayC7);
        }else{
            tv_repair_item.setTextColor(Color.parseColor("#404040"));
            view.setBackgroundResource(R.color.white);
        }
        return view;
    }
}
